Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pbf

Package Overview
Dependencies
Maintainers
28
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pbf

a low-level, lightweight protocol buffers implementation in JavaScript

  • 3.3.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
28
Created

What is pbf?

The pbf npm package is a low-level library for reading and writing Protocol Buffers (protobuf), a language-neutral, platform-neutral, extensible mechanism for serializing structured data. It is designed to be both efficient in performance and small in size, making it ideal for applications like map data processing in browsers or on servers.

What are pbf's main functionalities?

Reading Protocol Buffers

This code sample demonstrates how to read data from a Protocol Buffers file. It uses the Pbf instance to parse the buffer based on predefined tags and assigns the parsed data to a JavaScript object.

const Pbf = require('pbf');
const { readFileSync } = require('fs');

const buffer = readFileSync('data.pbf');
const pbf = new Pbf(buffer);
const data = pbf.readFields(readData, {});

function readData(tag, data, pbf) {
  if (tag === 1) data.name = pbf.readString();
  else if (tag === 2) data.version = pbf.readVarint();
}

Writing Protocol Buffers

This code sample shows how to write data to a Protocol Buffers file. It creates a new Pbf instance, writes data into it by specifying tags, and then writes the serialized data to a file.

const Pbf = require('pbf');
const { writeFileSync } = require('fs');

const data = { name: 'Example', version: 1 };
const pbf = new Pbf();
writeData(data, pbf);
pbf.finish();

writeFileSync('output.pbf', Buffer.from(pbf.buffer));

function writeData(obj, pbf) {
  pbf.writeStringField(1, obj.name);
  pbf.writeVarintField(2, obj.version);
}

Other packages similar to pbf

Keywords

FAQs

Package last updated on 03 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc